local skel = fk.CreateSkill {
  name = "rmt__lueshi",
}

Fk:loadTranslationTable{
  ["rmt__lueshi"] = "略师",
  [":rmt__lueshi"] = "出牌阶段限一次，你可以视为使用一张目标唯一的普通锦囊牌。若你本阶段发动过本技能：你使用基本牌后，重置此技能；你获得牌后，本技能本回合无法以上述方式重置。",

  ["#rmt__lueshi"] = "略师：视为使用一张目标唯一的普通锦囊牌",
  ["@@rmt__lueshi-turn"] = "略师:禁重置",
}

skel:addEffect("viewas", {
  prompt = "#rmt__lueshi",
  mute_card = false,
  interaction = function (self, player)
    local all_choices = table.filter(Fk:getAllCardNames("t"), function (name)
      return not Fk:cloneCard(name).multiple_targets
    end)
    local choices = player:getViewAsCardNames(skel.name, all_choices)
    return UI.CardNameBox {all_choices = all_choices, choices = choices}
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, cards, player)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = skel.name
    return card
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  enabled_at_play = function (self, player)
    return player.phase == Player.Play and player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryPhase) > 0 then
      return data.card.type == Card.TypeBasic and target == player and player:getMark("@@rmt__lueshi-turn") == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryPhase)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(skel.name, true) and player:usedSkillTimes(skel.name, Player.HistoryPhase) > 0
    and player:getMark("@@rmt__lueshi-turn") == 0  then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Card.PlayerHand and #move.moveInfo > 0 then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__lueshi-turn", 1)
  end
})

return skel
